using System;
using System.Drawing;
using System.Reflection;
using GriffinNav.GPS;

namespace GriffinNav.UI
{
    public class Arrow
    {
        private static Size mSize = new Size(32, 32);

        private Rectangle mScreenPosition;
        private Rectangle mScreenRectangle;

        private Bitmap mArrow0 = null;
        private Bitmap mArrow22_5 = null;
        private Bitmap mArrow45 = null;
        private Bitmap mArrow67_5 = null;
        private Bitmap mArrow90 = null;
        private Bitmap mArrow112_5 = null;
        private Bitmap mArrow135 = null;
        private Bitmap mArrow157_5 = null;
        private Bitmap mArrow180 = null;
        private Bitmap mArrow202_5 = null;
        private Bitmap mArrow225 = null;
        private Bitmap mArrow247_5 = null;
        private Bitmap mArrow270 = null;
        private Bitmap mArrow292_5 = null;
        private Bitmap mArrow315 = null;
        private Bitmap mArrow337_5 = null;

        private const string M_NAMESPACE = "GriffinNav";

        private VelocityDirection mDirection = VelocityDirection.N;

        public Arrow(Rectangle screenRectangle)
        {
            mScreenPosition = new Rectangle(
                    (screenRectangle.Width / 2) - (mSize.Width / 2),
                    (screenRectangle.Height / 2) - (mSize.Height / 2),
                     mSize.Width, mSize.Height);

            mScreenRectangle = screenRectangle;

            loadImages();
        }

        private void loadImages()
        {
            mArrow0 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow0.bmp"));
            mArrow22_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow22_5.bmp"));
            mArrow45 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow45.bmp"));
            mArrow67_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow67_5.bmp"));
            mArrow90 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow90.bmp"));
            mArrow112_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow112_5.bmp"));
            mArrow135 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow135.bmp"));
            mArrow157_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow157_5.bmp"));
            mArrow180 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow180.bmp"));
            mArrow202_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow202_5.bmp"));
            mArrow225 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow225.bmp"));
            mArrow247_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow247_5.bmp"));
            mArrow270 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow270.bmp"));
            mArrow292_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow292_5.bmp"));
            mArrow315 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow315.bmp"));
            mArrow337_5 = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream(M_NAMESPACE + ".Images.Arrow337_5.bmp"));
        }

        public VelocityDirection Direction
        {
            set
            {
                mDirection = value;
            }
        }

        public Bitmap DirectionArrow
        {
            get
            {
                switch (mDirection)
                {
                    case VelocityDirection.N:
                        return mArrow0;
                    case VelocityDirection.NNE:
                        return mArrow22_5;
                    case VelocityDirection.NE:
                        return mArrow45;
                    case VelocityDirection.ENE:
                        return mArrow67_5;
                    case VelocityDirection.E:
                        return mArrow90;
                    case VelocityDirection.ESE:
                        return mArrow112_5;
                    case VelocityDirection.SE:
                        return mArrow135;
                    case VelocityDirection.SSE:
                        return mArrow157_5;
                    case VelocityDirection.S:
                        return mArrow180;
                    case VelocityDirection.SSW:
                        return mArrow202_5;
                    case VelocityDirection.SW:
                        return mArrow225;
                    case VelocityDirection.WSW:
                        return mArrow247_5;
                    case VelocityDirection.W:
                        return mArrow270;
                    case VelocityDirection.WNW:
                        return mArrow292_5;
                    case VelocityDirection.NW:
                        return mArrow315;
                    case VelocityDirection.NNW:
                        return mArrow337_5;
                    default:
                        return mArrow0;
                }
            }
        }

        public static Size Size
        {
            get
            {
                return mSize;
            }
        }

        public Rectangle ScreenPosition
        {
            get
            {
                return mScreenPosition;
            }
            set
            {
                mScreenPosition = value;
            }
        }

        public Rectangle ScreenRectangle
        {
            get
            {
                return mScreenRectangle;
            }
            set
            {
                mScreenRectangle = value;
                mScreenPosition = new Rectangle(
                    (mScreenRectangle.Width / 2) - (mSize.Width / 2),
                    (mScreenRectangle.Height / 2) - (mSize.Height / 2),
                     mSize.Width, mSize.Height);
            }
        }
    }
}
